package com.baizhi.abstractx;

public class AbstarctDemo {

    public static void main(String[] args) {
        //Dog dog = new Dog("大黄", 3, "黄");

        //Cat cat = new Cat("咪咪", 2, "黑");

       // dog.eat();
       // cat.eat();

        Animal a1 = new Dog("大黑",2,"黑白");
        a1.eat();

//        Animal a2 = new Animal();
//        a2.eat();

    }
}

// 动物
abstract class Animal {
    String name;
    int age;
    String color;


    public Animal(String name, int age, String color) {
        this.name = name;
        this.age = age;
        this.color = color;
    }

    void drink() {
        System.out.println(color + "色的" + age + "岁的" + name + "在喝水");
    }

    /**
     * 当父类中的方法的方法体无法满足子类的使用，那么就可以省略父类的方法体，同时连{}也省略，只需要子类重写即可
     * 但是这样不符合语法规范，那么此时用abstarct来修饰即可，被abstarct修饰的方法就是抽象方法，
     * 抽象方法必须放在抽象类中
     */
    abstract void eat();


  // abstract void eat(String food);


}

//狗
class Dog extends Animal {

    public Dog(String name, int age, String color) {
        super(name, age, color);
    }


    public void brand() {
        System.out.println("这只狗在朝着陌生人叫唤");
    }

    @Override
    void eat() {
        System.out.println(age + "岁的" + color + "色的" + name + "正在吃骨头");
    }
}

//猫
class Cat extends Animal {

    public Cat(String name, int age, String color) {
        super(name, age, color);
    }


    public void catchMouse() {
        System.out.println("这只猫在抓老鼠");
    }

    @Override
    void eat() {
        System.out.println(age + "岁的" + color + "色的" + name + "正在吃鱼");
    }
}

abstract class Fish extends Animal{
    public Fish(String name, int age, String color) {
        super(name, age, color);
    }


}
